﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SnippetPlugin.Forms {
    public partial class Select : Form {
        private Data.Config _config;
        private Data.Snippet _snippet;

        public Select() {
            InitializeComponent();
        }

        public Select(Data.Config config, Data.Snippet snippet)
            : this() {
            _config = config;
            _snippet = snippet;
            BindConfig();
        }

        private void BindConfig() {
            lbSnippet.ValueMember = "Id";
            lbSnippet.DisplayMember = "Name";
            lbSnippet.DataSource = _config.Snippets;
        }

        private void lbSnippet_DoubleClick(object sender, EventArgs e) {
            if(lbSnippet.SelectedValue != null) {
                Data.Snippet snippet = _config.Snippets.First(s => s.Id == (Guid)lbSnippet.SelectedValue);
                snippet.CopyTo(_snippet);
                DialogResult = DialogResult.OK;
            }
        }
    }
}
